<template>
  <el-card class="publish-container">
    <div slot="header" class="clearfix">
      <div class="head">修改内容</div>
    </div>
    <el-form label-width="80px"
    ref="myForm"
    :rules="rules"
    :model="form">
      <el-form-item label="标题" prop="title">
        <el-input v-model="form.title"></el-input>
      </el-form-item>
      <el-form-item label="内容" prop="content">
        <quill-editor v-model="form.content" :options="editorOption"></quill-editor>
      </el-form-item>
      <el-form-item v-if="form.coverType > 0">
        <el-row>
          <el-col :span="6" v-for="(item, idx) in form.coverType" :key="item">
            {{idx}}
            <my-cover v-model="form.coverImages[idx]"/>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="Ypush">发布</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script>
// 导入样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// 导入组件
import { quillEditor } from 'vue-quill-editor'
export default {
  name: 'AddArticle',
  props: ['id'],
  components: {
    quillEditor
  },
  data () {
    return {
      Info: {},
      // 富文本配置对象
      editorOption: {
        modules: {
          // 配置工具栏
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'],
            ['blockquote', 'code-block'],
            [{ header: 1 }, { header: 2 }],
            [{ list: 'ordered' }, { list: 'bullet' }],
            [{ indent: '-1' }, { indent: '+1' }],
            ['image']
          ]
        }
      },
      form: {
        title: '随心而动随刃而行',
        content: '嚣张6666666666666666',
        data: new Date()
      },
      rules: {
        title: [
          { required: true, message: '请输入文章标题', trigger: 'blur' },
          { min: 5, max: 30, message: '长度在5到30之间', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入文章内容', trigger: 'blur' },
          { min: 20, max: 30000, message: '最少20个字', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async Ypush () {
      const id = this.Info.id
      try {
        this.$http.patch('http://localhost:3000/wen/' + id, this.form).then((res) => {
          console.log(res)
        })
      } catch (err) {
        console.log(err)
        this.$message.error('发布失败')
      }
    }
  },
  mounted () {
    this.Info = this.$route.query.Info
    this.Info = JSON.parse(localStorage.getItem('Info'))
  }
}
</script>
<style lang="less" scoped>
// 在父组件中去设置子组件的样式，加上/deep/ 实现穿透功能
.publish-container /deep/ .ql-container{
  height: 300px;
}
.publish-container /deep/ .ql-toolbar.ql-snow{
  padding: 0 8px;
}
  .head{
          width: 100%;
      height: 30px;
      line-height: 30px;
  }

</style>
